/*
 * @Description: 描述
 * @Author: cy
 * @Date: 2024/5/12
 */

const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');

let f='/0214/1715701305788'
const directoryPath = path.join(__dirname, `./${f}`); // 替换为你的目录路径
let arr=[]
// 异步
// fs.readdir(directoryPath, (err, files) => {
//   if (err) {
//     return console.log('Unable to scan directory: ' + err);
//   }
//   // 文件名存储在files数组中
//   files.forEach((file) => {
//     console.log(file);
//       let url=`file '/Users/chaoyang/传说中的神兽/0213/1707828014729/${file}'`
//       arr.push(url)
//   });
// });
exec('ls -l', (error, stdout, stderr) => {
  if (error) {
    console.error(`执行的错误: ${error}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
  if (stderr) {
    console.log(`stderr: ${stderr}`);
  }
});

//
// for (let i = 1; i < 3520; i++) {
//   let url=`file '/Users/chaoyang/传说中的神兽/0213/1707828014729/${JSON.stringify(i).padStart(6,0)}.ts'`
//   arr.push(url)
// }
//
// for (let i = 1; i < 1000; i++) {
//   let url=`file '/Users/chaoyang/Downloads/20240217003325.m3u8.qqv/segment_${i}.ts'`
//   arr.push(url)
// }

// 同步
const files = fs.readdirSync(directoryPath);
files.forEach((file) => {
  console.log(file);
  if(file?.includes('ts')){

    let url=`file '/Users/chaoyang/传说中的神兽/cy/media/code/react/reactCli/cy_server/${f}/${file}'`
    arr.push(url)
  }
});

  fs.writeFile('./text.txt', arr.join('\n'), err => {
    if(err) {
      console.log('写入失败')
    } else {
      console.log('写入成功');
    }
  })
// console.log(arr.join('\n'))






